package com.hq.service;

import com.hq.bean.Student;
import com.hq.dao.StuDAO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StuServiceImpl implements StuService {

    @Resource
    private StuDAO stuDAO;
    @Override
    public List list(Map map) {
        return stuDAO.list(map);
    }

    @Override
    public List cityList(Integer pid) {
        return stuDAO.cityList(pid);
    }

    @Override
    public List courseList() {
        return stuDAO.courseList();
    }

    @Override
    public int add(Student stu, Integer[] cids) {
        // 添加主表 获取主键id
      int i= stuDAO.addStu(stu);
      if(cids.length>0){
          // 添加中间表
          Map map=new HashMap();
          map.put("sid",stu.getSid());
          map.put("cids",cids);
          stuDAO.addMi(map);
      }
        return i;
    }
}
